package com.zed.games.answer;

import com.zed.api.common.collection.MemberGroup;
import com.zed.api.games.GameLevel;
import com.zed.api.games.GameLevels;
import com.zed.api.games.answer.action.AnswerAction;
import com.zed.api.games.answer.show.AnswerShowWorld;

import java.io.Serial;
import java.util.List;
import java.util.Objects;

/**
 * 答题游戏关卡
 *
 * @author Zed
 */
public class AnswerGameLevels extends MemberGroup<GameLevel<AnswerShowWorld, AnswerAction>> implements GameLevels<AnswerShowWorld, AnswerAction> {

    @Serial
    private static final long serialVersionUID = -1022902873012857762L;

    public AnswerGameLevels(List<GameLevel<AnswerShowWorld, AnswerAction>> items) {
        super(items);
    }

    @Override
    public GameLevel<AnswerShowWorld, AnswerAction> findGameLevel(int level) {
        return this.findByFilter(el -> Objects.equals(el.getCurrentLevel(), level));
    }

    @Override
    public GameLevel<AnswerShowWorld, AnswerAction> getFirst() {
        return this.getItems().stream().findFirst().orElse(null);
    }

    @Override
    public GameLevel<AnswerShowWorld, AnswerAction> getEnd() {
        return this.getItems() == null || this.getItems().isEmpty()
                ? null : this.getItems().get(this.size() - 1);
    }
}
